package com.wsh.controller.sys;

import com.wsh.dto.sys.RoleMenuDto;
import com.wsh.utils.JsonResult;
import com.wsh.vo.sys.RoleMenuVo;
import com.wsh.sys.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/sys/roleMenu")
@Api(tags = "系统：角色关联菜单")
public class RoleMenuController {

    @Autowired
    private RoleMenuService roleMenuService;

    @GetMapping("/list")
    @ApiOperation(value = "角色关联菜单列表", notes = "查询数据库中的记录", httpMethod = "GET",response = Object.class)
    public Object list(RoleMenuDto roleMenuDto) {
        return JsonResult.success(roleMenuService.getList(roleMenuDto));
    }

    /**
     * 用户权限保存
     * @param roleMenuVo
     * @return
     */
    @PreAuthorize("@el.check('roleMenu:save')")
    @PostMapping("/saveRole")
    @ApiOperation(value = "保存角色关联菜单")
    public Object saveRole(@RequestBody RoleMenuVo roleMenuVo) {
        return JsonResult.success(roleMenuService.saveRoleMenus(roleMenuVo));
    }

    /**
     * 获取用户权限树
     * @param roleId
     * @return
     */
    @PreAuthorize("@el.check('roleMenu:tree')")
    @GetMapping("/getMenusByRole")
    @ApiOperation(value = "获取用户权限树")
    public Object getMenusByRole(@RequestParam String roleId) {
        return JsonResult.success(roleMenuService.getMenusByRole(roleId));
    }

}
